import cv2 as cv
import numpy as np
filename=r'F:\AI\lena.jpg'
img=cv.imread(filename)
cv.imshow("sourceimage",img)
p1=cv.GaussianBlur(img,(3,3),0)#高斯滤波
cv.imshow("GaussianBlur3*3",p1)
p2=cv.medianBlur(img,5)#中值滤波
cv.imshow("medianBlur",p2)
p3=cv.blur(img,(3,3))  #平均滤波
cv.imshow("Blur",p3)

gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow("gray",gray)

sobelx=cv.Sobel(gray,cv.CV_64F,1,0,ksize=3)#sobel算子x方向检测
sobely=cv.Sobel(gray,cv.CV_64F,0,1,ksize=3)#sobel算子y方向检测
sobelxy=cv.Sobel(gray,cv.CV_64F,1,1,ksize=3)#sobel算子xy两个方向检测
cv.imshow("sobelx",sobelx)
cv.imshow("sobely",sobely)
cv.imshow("sobelxy",sobelxy)

canny=cv.Canny(gray,50,100)
cv.imshow("Canny",canny)

cv.waitKey()
cv.destroyAllWindows()